<?php
 strtolower(basename($_SERVER['PHP_SELF'])) == 'Comment.class.php' && header('Location:http://' . $_SERVER['HTTP_HOST']); //禁止直接访问本页

include('db.php');
include('BeanUtil.php');

class Recycle{
	public $id;
	public $userid;
    public $content;
    public $docid;
    public $delkb;
    public $wrtdt;
    public $wrttm;
	public $title;
    public $author;
	
	public static  function getCommentList(){
		    $sql="select c.*,d.title,d.author from comment c,document d where c.docid=d.id and c.delkb=1 order by c.wrtdt,c.wrttm ";
		    $mydb=new MySql();
    		$resultArray=$mydb->query($sql);
    		$arr=array();
    		$idx=0;
    		 while($data = $mydb->fetch($resultArray)){
   					$bean = new Recycle();
   					BeanUtil::fetch($data, $bean);
   					$arr[$idx++] = $bean;
   		     }
    		return $arr;
	}
	
	public static  function getDocsList(){
		    $sql="select d.id,d.title,d.author from document d where d.delkb=1 order by d.id ";
		    $mydb=new MySql();
    		$resultArray=$mydb->query($sql);
    		$arr=array();
    		$idx=0;
    		 while($data = $mydb->fetch($resultArray)){
   					$bean = new Recycle();
   					BeanUtil::fetch($data, $bean);
   					$arr[$idx++] = $bean;
   		     }
    		return $arr;
	}
	
	public static function delComtById($id=''){
			$upsql="delete from comment where id ={$id}";
			//echo $upsql;exit;
			$mydb=new MySql();
			$exe=$mydb->query($upsql);
			if($exe)
			   return true;
            else
				return false;
    }
	
	public static function recComtById($id=''){
			$upsql="UPDATE  comment SET  delkb = 0 WHERE  id ={$id}";
			$mydb=new MySql();
			$exe=$mydb->query($upsql);
			if($exe)
			   return true;
            else
				return false;
    }
	
	public static function delDocComtById($id=''){
			$upsql="delete from document where id ={$id}";
			//echo $upsql;exit;
			$mydb=new MySql();
			$exe=$mydb->query($upsql);
			if($exe)
			   return true;
            else
				return false;
    }
	
	public static function recDocComtById($id=''){
			$upsql="UPDATE  document SET  delkb = 0 WHERE  id ={$id}";
			$mydb=new MySql();
			$exe=$mydb->query($upsql);
			if($exe)
			   return true;
            else
				return false;
    }
	
}

?>
